using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Data.Odbc;
using System.Data.OleDb;

namespace SqlPrompt
{
	public enum AdoInterface
	{
		Sql, Odbc, OleDb
	}

	public class DbConnectionInfo
	{
		public string Name = "";
		public AdoInterface AdoInterface = AdoInterface.Sql;
		public string ConnectionString = "";
	}

	class DbFactory
	{
		public static IDbConnection CreateDbConnection(DbConnectionInfo config)
		{
			switch (config.AdoInterface)
			{
				case AdoInterface.Sql: return new SqlConnection(config.ConnectionString);
				case AdoInterface.Odbc: return new OdbcConnection(config.ConnectionString);
				case AdoInterface.OleDb: return new OleDbConnection(config.ConnectionString);
			}

			throw new DbConfigException("Unknown ADO interface");
		}

		public static IDbCommand CreateDbCommand(DbConnectionInfo config)
		{
			switch (config.AdoInterface)
			{
				case AdoInterface.Sql: return new SqlCommand();
				case AdoInterface.Odbc: return new OdbcCommand();
				case AdoInterface.OleDb: return new OleDbCommand();
			}

			throw new DbConfigException("Unknown ADO interface");
		}
	}

	class DbConfigException : Exception
	{
		public DbConfigException(string message) : base(message) { }
	}
}
